<?php
session_start();
isLogin();
if(!$_SESSION['super']){reload_js("权限不足","index.php");}

if(isset($_POST["Submits"])){
	$isSup=0;
	if($_POST['m_isSuperAdmin']){$isSup=1;}
	if($_REQUEST['m_id']){
		$pre="修改";
		$sql="update ".$prefix."member set m_username='".$_POST['m_username']."',m_psw='".md5($_POST['m_psw'])."',m_isSuperAdmin=".$isSup." where m_id=".$_REQUEST['m_id'];
	}else{
		$pre="添加";
		$sql="insert into ".$prefix."member (m_username,m_psw,m_isAdmin,m_isSuperAdmin) values('".$_POST['m_username']."','".md5($_POST['m_psw'])."',1,".$isSup.")";
	}
	if(mysql_query($sql)){
		reload_js($pre."成功","index.php?cmd=viewAdmin");
	}else{
		reload_js($pre."失败，原因：程序错误，请联系技术人员进行修改","index.php");
	}
}

if($_REQUEST['m_id']){
	$sql="select * from ".$prefix."member where m_id='".$_REQUEST['m_id']."'";
	$result=mysql_query($sql);
	$super=true;
	if($arr=mysql_fetch_array($result)){
		$username=$arr['m_username'];
		if(!$arr['m_isSuperAdmin']){$super=false;}
	}
}

?>
<script language="javascript" src="../templates/<?php echo $moban;?>/js/common.js"></script>
<script language="javascript">
changeWebTitle('管理员添加');
</script>

<div class="ContentRight">
    <div class="ContentRightTop">
      <div class="BarLeft"></div>
      <div class="ContentRightTopText">管理员添加</div>
      <div class="BarRight"></div>
      <div class="Cal"></div>
    </div>
    <div class="ContentRightBox">
	<form action="" method="post" name="passmodify">
      <table width="100%" cellpadding="0" class="Table1" bordercolor="#4ab902" border="1" cellspacing="0">
        
        <tr>
          <td width="22%" height="25" align="right">账号：</td>
          <td width="78%">            <input name="m_username" type="text" id="m_username" maxlength="20" value="<?php echo $username;?>"/>          </td>
        </tr>
        <tr>
          <td height="25" align="right">密码：</td>
          <td>            <input name="m_psw" type="text" id="m_psw"  maxlength="20"/>          </td>
        </tr>
        <tr>
          <td height="25" align="right">超级管理员：</td>
          <td>
            <label>
            <input name="m_isSuperAdmin" type="radio" value="1" checked="checked" />
是</label>
            <label>
            <input type="radio" name="m_isSuperAdmin" value="0" <?php if(!$super){ echo "checked";}?>/>
否</label></td>
        </tr>
        
        <tr>
          <td height="25" align="right">版权所有：</td>
          <td><a href="http://www.fengsh8.com" target="_blank">风尚淘客程序</a></td>
        </tr>
        <tr>
          <td height="25" align="right">&nbsp;</td>
          <td>
            <input name="Submits" type="submit" id="Submits" value=" 提  交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input name="Reset" type="reset" id="Reset" value=" 重 置 " />         </td>
        </tr>
      </table>
	  </form>
    </div>
    <div class="Cal"></div>
  </div>